// hyb_yl/my/my.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    exa: "",
    zid: "",
    twitters: 1,
    state: 1,
    cpm: true,
    isLoading: !0
  },
  iconlist: function (e) {
    const url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url,
    })
  },
  tovip:function(){
    wx.navigateTo({
      url: '/hyb_yl/backstageServices/pages/vip/vip',
    })
    
  },
  saoyisao: function () {
    var that = this;
    wx.scanCode({ //扫描微信API
      success(res) { //成功
        console.log(res) //输出回调信息
        var code_num = res.result;
        app.util.request({
          'url': "entry/wxapp/index.goods_ids",
          data: {
            code_num: code_num
          },
          success: function (res) {
            if (res.data == '') {
              wx.showModal({
                title: '提示',
                content: '找不到该商品'
              })
            } else {
              wx.navigateTo({
                url: '/hyb_yl/mysubpages/pages/product/product?fid=&sid=' + res.data,
              })
            }
          }
        })
      },
      fail(res) {
        wx.showToast({
          title: '失败',
          icon: 'error',
          duration: 1000
        })
      },
    })
  },
  //我的问诊
  wodeWenzhen(e) {
    var that = this
    var keywords = e.currentTarget.dataset.keywords
    wx.navigateTo({
      url: "/hyb_yl/mysubpages/pages/wodezixun/wodezixun?type=wenzhen&key_words=" + keywords
    });
  },
  //我的服务
  servelist(e) {
    var that = this
    let txt = e.currentTarget.dataset.tit
    var type = e.currentTarget.dataset.type
    if (txt == "报告解读") {
      wx.navigateTo({
        url: "/hyb_yl/mysubpages/pages/unscramble/unscramble"
      });
    } else if (txt == "手术安排") {
      wx.navigateTo({
        url: "/hyb_yl/mysubpages/pages/wodezixun/wodezixun?type=shoushu&key_words=shoushukuaiyue"
      });
    } else if (txt == "医生卡") {
      wx.navigateTo({
        url: "/hyb_yl/backstageServices/pages/yearcardlist/yearcardlist"
      });
    } else if (txt == "我的动态") {
      wx.navigateTo({
        url: "/hyb_yl/mysubpages/pages/myTidings/myTidings"
      });
    } else if (txt == "我的患教") {
      wx.navigateTo({
        url: "/hyb_yl/mycenter/pages/myMedical/myMedical"
      });
    } else if (txt == "健康档案") {
      wx.navigateTo({
        url: "/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?type=1&gren=1"
      });
    } else if (txt == "我的报告") {
      wx.navigateTo({
        url: "/hyb_yl/mysubpages/pages/report/report"
      });
    } else if (txt == "报告对比") {
      wx.navigateTo({
        url: "/hyb_yl/mysubpages/pages/report/report"
      });
    } else if (txt == "健康分析") {
      wx.showToast({
        title: '开发中...',
        icon: "none"
      })
    } else if (txt == "我的处方") {
      wx.navigateTo({
        url: "/hyb_yl/mysubpages/pages/my_hzprescription/my_hzprescription"
      });
    } else if (txt == "我的优惠券") {
      wx.navigateTo({
        url: "/hyb_yl/mycenter/pages/myCoupon/myCoupon"
      });
    } else if (txt == "我的会员卡") {
      wx.navigateTo({
        url: "/hyb_yl/backstageServices/pages/vip/vip"
      });
    } else if (txt == "私人医生") {
      // wx.showToast({
      //   title: '开发中...',
      //   icon: "none"
      // })
      wx.navigateTo({
        url: '/hyb_yl/mycenter/pages/followDoc/followDoc?typs=siren_doc',
      })
    } else if (txt == "免费兑礼") {
      wx.showToast({
        title: '开发中...',
        icon: "none"
      })
    } else if (txt == "邀请有礼") {
      wx.showToast({
        title: '开发中...',
        icon: "none"
      })
    } else if (txt == "专家入口") {
      
      if (that.data.zid == "" || that.data.exa == 0 || that.data.exa == 2 || that.data.zid == 'undefined' || that.data.zid == undefined) {
        wx.navigateTo({
          url: '/hyb_yl/backstageOther/pages/myRenZheng/myRenZheng?zid=' + that.data.zid + '&exa=' + that.data.exa,
        })
      } else {
        wx.reLaunch({
          url: "/hyb_yl/doctorHome/pages/home/home"
        });
      }

    } else if (txt == "机构入口") {

      if (this.data.info.is_hospital) {
        wx.navigateTo({
          url: '/hyb_yl/mycenter/pages/Organ/Organ',
        })
      } else {
        wx.navigateTo({
          url: '/hyb_yl/mycenter/pages/organApply/organApply',
        })
      }
    } else if (txt == "推客入口") {
      wx.showToast({
        title: '开发中...',
        icon: "none"
      })

    } else if (txt == '绿通入口') {
      var is_daozhen = that.data.info.is_daozhen;
      if (is_daozhen) {
        wx.navigateTo({
          url: '/hyb_yl/lvtongserver/pages/index/index',
        })
      } else {
        wx.showToast({
          title: '您暂未成为绿通人员',
          icon: "none"
        })
      }
    } else if (txt == '药师入口') {
      var is_yaoshi = that.data.info.is_yaoshi;
      if (is_yaoshi) {
        wx.navigateTo({
          url: '/hyb_yl/yaoshi/pages/index/index',
        })
      } else {
        wx.showToast({
          title: '您暂未成为药师',
          icon: "none"
        })
      }
    } else if (txt == '消息设置') {
      wx.navigateTo({
        url: '/hyb_yl/mysubpages/pages/set_jurisdiction/set_jurisdiction',
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getfooter()
    var that = this
    var index = options.index
    that.setData({
      index: index
    })
    
    app.util.request({
      'url': 'entry/wxapp/user.info',
      data: {
        openid: wx.getStorageSync('openid'),
      },
      success: function (res) {
        console.log(res)
        that.setData({
          phone: res.data.u_phone,
          info: res.data
        })
      }
    })
    app.util.request({
      'url': "entry/wxapp/user.getcenter",
      data: {
        type: 0
      },
      success: function (res) {
        that.setData({
          server: res.data,
          isLoading: !1
        })
      }
    })
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    wx.login({
      success(res) {
        console.log(res)
        wx.setStorageSync('code', res.code)
        var code = res.code
        var code = wx.getStorageSync('code')
        var sessionKey = wx.getStorageSync('sessionKey')
        if (res.code) {
          wx.getUserInfo({
            success: function (res) {
              console.log(res)
              var encryptedData = res.encryptedData
              var iv = res.iv
              //3.解密用户信息 获取unionId
              app.util.request({
                url: "entry/wxapp/authorize.getuid",
                data: {
                  code: code,
                  encryptedData: encryptedData,
                  iv: iv
                },
                success: function (e) {
                  console.log(e)
                  wx.setStorageSync('sessionKey', e.data.userinfo.session_key)
                }
              })
            },
            fail: function () {
              console.log('获取用户信息失败')
            }
          })
        }
      }
    })
  },
  link: function (e) {
    console.log("健康报告",e)
    var url = e.currentTarget.dataset.url;
    var title = e.currentTarget.dataset.title;
    
    var that = this
    if (url == '/hyb_yl/doctorHome/pages/home/home') {
      if (that.data.zid == "" || that.data.exa == 0 || that.data.exa == 2 || that.data.zid == 'undefined' || that.data.zid == undefined) {
        wx.navigateTo({
          url: '/hyb_yl/backstageOther/pages/myRenZheng/myRenZheng?zid=' + that.data.zid + '&exa=' + that.data.exa,
        })
      } else {
        wx.reLaunch({
          url: url
        });
      }
    } else if (url == '/hyb_yl/jigou/pages/index/index') {
      if (this.data.info.is_hospital == '审核中') {
        wx.showToast({
          title: '审核中',
          icon: "none"
        })
      } else if (this.data.info.is_hospital) {
        wx.navigateTo({
          url: url,
        })
      } else {
        wx.navigateTo({
          url: '/hyb_yl/mycenter/pages/organApply/organApply',
        })
      }
    } else if (url == '/hyb_yl/yaoshi/pages/index/index') {
      var is_yaoshi = that.data.info.is_yaoshi;
      if (is_yaoshi == '审核中' || is_yaoshi == '审核拒绝' || is_yaoshi == '暂停中') {
        wx.showToast({
          title: is_yaoshi,
          icon: "none"
        })
      } else if (is_yaoshi) {
        wx.navigateTo({
          url: url,
        })
      } else {
        wx.showToast({
          title: '您暂未成为药师',
          icon: "none"
        })
      }
    } else if (url == '/hyb_yl/mycenter/pages/twitterApply/twitterApply') {
      //查询推客是否开启
      app.util.request({
        'url': 'entry/wxapp/tuike.ifopentuike',
        success: function (res) {
          console.log(res)
          if (res.data == 2) {
            wx.showToast({
              title: '未开启推客',
              icon: "none"
            })
            return false;
          }
          if (res.data == 1) {

            app.util.request({
              'url': 'entry/wxapp/tuike.iftuike',
              data: {
                openid: wx.getStorageSync('openid')
              },
              success: function (res) {
                console.log(res)
                var id = res.data.id
                if (res.data !== 0) {
                  wx.navigateTo({
                    url: '/hyb_yl/mycenter/pages/Twitter/Twitter?id=' + id,
                  })
                } else {
                  wx.navigateTo({
                    url: url,
                  })
                }
              },
              fail: function (err) {
                console.log(err)
              },

            })

          }
          if (res.data == 0) {
            wx.showToast({
              title: '推客入口已关闭',
              icon: "none"
            })
            return false;
          }
        },
        fail: function (err) {
          console.log(err)
        },

      })
      return false;
    } else if (url == '/hyb_yl/lvtongserver/pages/index/index') {
      app.util.request({
        'url': "entry/wxapp/user.is_green",
        data: {
          openid: wx.getStorageSync('openid')
        },
        success: function (res) {
          if (res.data.is_green) {
            wx.navigateTo({
              url: url,
            })
          } else {
            wx.showToast({
              title: '您暂未成为绿通人员',
              icon: "none"
            })
            return false;
          }
        }
      })
    } else if(url == '/hyb_yl/mysubpages/pages/backstageIndex/backstageIndex'){
      if (that.data.zid == "" || that.data.exa == 0 || that.data.exa == 2 || that.data.zid == 'undefined' || that.data.zid == undefined) {
        wx.navigateTo({
          url: '/hyb_yl/backstageOther/pages/myRenZheng/myRenZheng?zid=' + that.data.zid + '&exa=' + that.data.exa,
        })
      } else {
        wx.reLaunch({
          url: "/hyb_yl/doctorHome/pages/home/home"
        });
      }
    }else if (url != '') {
      wx.navigateTo({
        url: url,
      })
    } else {
      wx.showToast({
        title: '开发中...',
        icon: "none"
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getjigouif()
    // this.getBase();
    // this.getMyifkefu()
    // this.getMyvt();
    // this.getKeshi();
    // this.getMyxfjl();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getIfdoc()
    var openid = wx.getStorageSync('openid');
    if(openid == '')
    {
      wx.showModal({
        cancelColor: '提示',
        content:"请先登录",
        success:function(con)
        {
          if(con.confirm)
          {
            wx.navigateTo({
              url: '/hyb_yl/sgin/sgin',
            })
          }else{
            wx.switchTab({
              url: '/hyb_yl/tabBar/index/index',
            })
          }
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    this.getBase();
    this.getMyvt();
    this.getKeshi();

    wx.showNavigationBarLoading();
    setTimeout(function () {
      wx.stopPullDownRefresh();
      wx.hideNavigationBarLoading();
    }, 1000)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */

  getMyxfjl: function () {
    var that = this;
    var openid = wx.getStorageSync('openid')
    var uniacid = app.siteInfo.uniacid;
    app.util.request({
      'url': 'entry/wxapp/Myxfjl',
      data: {
        openid: openid,
        uniacid: uniacid
      },
      success: function (res) {
        //console.log(res)
        that.setData({
          myxfjl: res.data.data,

        })
      },
      fail: function (err) {
        console.log(err)
      },

    })
  },
  //我的消费
  getMyvt: function () {
    var that = this;
    var openid = wx.getStorageSync('openid')
    //console.log(openid)
    app.util.request({
      'url': 'entry/wxapp/myvt',
      data: {
        openid: openid,
      },
      success: function (res) {
        //console.log(res)
        that.setData({
          myvt: res.data.data,
          openid: openid
        })
      },
      fail: function (err) {
        console.log(err)
      },

    })
  },
  bindPickerChange1: function (e) {
    var that = this;
    var dex = e.detail.value;
    var ids = that.data.keshiid;
    var id = ids[dex];
    console.log(id);
    var arrs = that.data.zhiwu; //新增
    var arr = arrs[dex]; //新增
    app.util.request({
      'url': 'entry/wxapp/Category2',
      data: {
        id: id
      },
      success: function (res) {
        console.log(res)
        that.setData({
          zhiwuss: res.data.data.name,
          pid: res.data.data.id
        })
      },
      fail: function (err) {
        console.log(err)
      },

    })
    that.setData({
      index: e.detail.value,
      id: id,
      zhiwuss: arr //新增
    })
  },
  bindPickerChange2: function (e) {
    var that = this;
    var dex = e.detail.value;
    var monery = that.data.monery;
    var pid = that.data.pid;
    var id = pid[dex];
    console.log(id);
    that.setData({
      indexx: dex,
      monerynum: monery[dex],
      id: id
    })
  },
  bindPickerChange: function (e) {
    this.setData({
      index: e.detail.value
    })
  },
  switchChange: function (e) {
    console.log('switch1 发生 change 事件，携带值为', e.detail.value)
  },
  radio: function (e) {
    //console.log(e)
    var ky_sex = e.detail.value
    this.setData({
      radioIndex: e.detail.value,
      ky_sex: ky_sex
    })
  },
  getBase: function () {
    var that = this;
    // console.log(app);
    app.util.request({
      'url': 'entry/wxapp/Base',
      success: function (res) {
        that.setData({
          baseinfo: res.data.data,
          bq_thumb: res.data.data.bq_thumb,
          bq_name: res.data.data.bq_name
        })
      },
      fail: function (err) {
        console.log(err)
      },

    })

  },
  getKeshi: function () {
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/Keshi',
      success: function (res) {
        that.setData({
          keshi: res.data.data.name,
          keshiid: res.data.data.id
        })
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },
  uploadpic: function (e) {
    var that = this
    var upload_picture_list = that.data.upload_picture_list
    wx.chooseImage({
      count: 3, // 默认9，这里显示一次选择相册的图片数量
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFiles = res.tempFiles
        //循环把图片加入上传列表
        for (var i in tempFiles) {
          tempFiles[i]['upload_percent'] = 0
          tempFiles[i]['path_server'] = ''
          upload_picture_list.push(tempFiles[i])
        }
        that.setData({
          upload_picture_list: upload_picture_list,
        })
        if (upload_picture_list.length == 3) {
          that.setData({
            hide: true
          })
        }
        //循环把图片上传到服务器 并显示进度
        for (var j in upload_picture_list) {
          if (upload_picture_list[j]['upload_percent'] == 0) {
            upload_file_server(that, upload_picture_list, j)
          }
        }
      }
    })

    function upload_file_server(that, upload_picture_list, j) {
      var uniacid = app.siteInfo.uniacid;
      // console.log(uniacid);
      var openid = wx.getStorageSync('openid');
      // console.log("开始上传" + j + "图片到服务器：")
      //console.log(upload_picture_list[j])
      var upload_task = wx.uploadFile({
        url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=msg_send_imgs&m=hyb_yl', //需要用HTTPS，同时在微信公众平台后台添加服务器地址
        filePath: upload_picture_list[j]['path'], //上传的文件本地地址
        name: 'file',
        formData: {
          'path': 'wxchat',
          openid: openid,
          uniacid: uniacid,
          i_type: 2
        }, //附近数据，这里为路径
        success: function (res) {
          // console.log(res)
          var data = res.data //字符串转化为JSON
          that.setData({
            thumb: data,
            upload_picture_list: upload_picture_list
          })
          // console.log("图片上传" + j + "到服务器完成：")
          //console.log(upload_picture_list[j]['path'])
        }
      })
      upload_task.onProgressUpdate((res) => {
        // console.log('上传进度', res.progress)
        // console.log('已经上传的数据长度', res.totalBytesSent)
        // console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
        upload_picture_list[j]['upload_percent'] = res.progress
        // console.log('第' + j + '个图片上传进度：' + upload_picture_list[j]['upload_percent'])
        //console.log(upload_picture_list)
        that.setData({
          upload_picture_list: upload_picture_list
        })

      })
    }
  },
  toast: function () {
    wx.redirectTo({
      url: '/hyb_yl/tabBar/index/index'
    })
  },
  toast1: function (e) {
    //console.log(e)
    wx.redirectTo({
      url: '/hyb_yl/tabBar/community/community'
    })
  },
  toast2: function () {
    wx.redirectTo({
      url: '/hyb_yl/mysubpages/pages/shop/shop'
    })
  },
  toast3: function () {
    var openid = wx.getStorageSync('openid');
    app.util.request({
      'url': 'entry/wxapp/Myphone',
      data: {
        openid: openid
      },
      success: function (res) {
        app.globalData.myphone = res.data.data
        app.globalData.openid = openid
      },
      fail: function (err) {
        console.log(err)
      },

    })
    setTimeout(function () {
      wx.redirectTo({
        url: '/hyb_yl/tabBar/my/my'
      })
    }, 350)
  },
  toast4() {
    wx.redirectTo({
      url: '/hyb_yl/userLife/pages/jibingyufang/jibingyufang'
    })
  },
  MyJifen() {
    wx.navigateTo({
      url: "/hyb_yl/backstageLifes/pages/integral/integral"
    });
  },
  // 二维码点击事件
  erClick: function () {
    var that = this
    var myxfjl = that.data.myxfjl
    if (myxfjl.u_type == 0) {
      wx.showToast({
        title: '暂无核销权限',
      })
    } else {
      wx.showActionSheet({
        itemList: ['预约核销'],
        success: function (res) {
          if (res.tapIndex == 0) {
            wx.navigateTo({
              url: '/hyb_yl/zhuanjiasubpages/pages/hexiao/hexiao',
            });
          }
        },
        fail: function (res) {
          console.log(res.errMsg)
        }
      })
    }

  },
  chufang: function (e) {
    var that = this
    console.log(e)
    var myzhuan = that.data.myzhuan
    var form_id = e.detail.formId
    var openid = wx.getStorageSync('openid')
    app.util.request({
      'url': 'entry/wxapp/UserFormId',
      'data': {
        form_id: form_id,
        openid: openid
      },
      success: function (res) {
        console.log(res)
        wx.navigateTo({
          url: '/hyb_yl/userLife/pages/my_prescription/my_prescription?id=' + myzhuan.zid,
        })
      }
    })
  },
  daClick: function (e) {
    var that = this
    var myzhuan = that.data.myzhuan
    console.log(myzhuan)
    var form_id = e.detail.formId
    var openid = wx.getStorageSync('openid')
    app.util.request({
      'url': 'entry/wxapp/UserFormId',
      'data': {
        form_id: form_id,
        openid: openid
      },
      success: function (res) {
        console.log(res)
        wx.navigateTo({
          url: '/hyb_yl/userLife/pages/wodehuida/wodehuida?zid=' + myzhuan.zid,
        })
      }
    })
  },
  zhuanDataClick: function () {
    var that = this
    var myzhuan = that.data.myzhuan
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiaziliao/zhuanjiaziliao?id=' + myzhuan.zid,
    })
  },
  zhuanWenClick: function () {
    var that = this
    var myzhuan = that.data.myzhuan
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/wentijine/wentijine?zid=' + myzhuan.zid,
    })
  },
  liaoClick: function () {
    var that = this
    var myzhuan = that.data.myzhuan
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/guanzhuwode/guanzhuwode?zid=' + myzhuan.zid,
    })
  },
  //理赔列表
  lipeiClick: function () {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/zhuan_huan/zhuan_huan',
    })
  },
  //查看是否提交了资料
  getIfdoc: function () {
    var that = this
    var openid = wx.getStorageSync('openid');
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.ifzj',
      data: {
        openid: openid
      },
      success: function (res) {
        console.log(res)
        if (res.data) {
          that.setData({
            zid: res.data.zid,
            exa: res.data.exa
          })
        } else {
          that.setData({
            zid: 0
          })
        }
      }
    })
  },
  Mykchufang: function () {
    //查询我的uid
    var that = this
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/my_hzprescription/my_hzprescription',
    })
  },

  kt: function (a) {
    var that = this
    var my_id = that.data.my_id
    if (a.detail.value == false) {
      var mydatype = 0
    }
    if (a.detail.value == true) {
      var mydatype = 1
    }
    app.util.request({
      'url': 'entry/wxapp/Myswitch1Change',
      data: {
        my_id: my_id,
        mydatype: mydatype,
        op: 'post'
      },
      success: function (res) {
        console.log(res)
        a.detail.value ? that.setData({
          flag: 1
        }) : that.setData({
          flag: 0
        });
      }
    })
  },
  getMyswitch1Change: function (my_id) {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/Myswitch1Change',
      data: {
        my_id: my_id,
        op: 'display'
      },
      success: function (res) {
        console.log(res)
        if (res.data.mydatype == 0) {
          that.setData({
            authStateBoo: false
          })
        }
        if (res.data.mydatype == 1) {
          that.setData({
            authStateBoo: true
          })
        }
      }
    })
  },
  //查询我是否是客服
  getMyifkefu: function () {
    var that = this
    var openid = wx.getStorageSync('openid')
    app.util.request({
      'url': 'entry/wxapp/Kfuid',
      success: function (res) {
        console.log(res)
        if (res.data.openid == openid) {
          that.setData({
            ifkefu: 1
          })
        } else {
          that.setData({
            ifkefu: 0
          })
        }
      }
    })
  },
  getfooter() {
    var that = this
    app.util.request({
      url: "entry/wxapp/index.footerlist",
      data: {
        openid: wx.getStorageSync('openid')
      },
      success: function (resing) {
        console.log(resing)
        let footers = {
          footerTab: that.data.index,
          footerlist: resing.data
        };
        that.setData({
          footer: footers
        })
      }
    })
  },
  getPhoneNumber: function (e) {
    console.log(e)
    var that = this
    var errMsg = e.detail.errMsg
    var iv = e.detail.iv
    var encryptedData = e.detail.encryptedData
    var code = wx.getStorageSync('code')
    var sessionKey = wx.getStorageSync('sessionKey')
    console.log(sessionKey, code)
    if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
      wx.showModal({
        title: '提示',
        showCancel: false,
        content: '未授权',
        success: function (res) {}
      })
    } else {
      app.util.request({
        'url': 'entry/wxapp/user.mdpwd',
        data: {
          iv: e.detail.iv,
          code: code,
          sessionKey: sessionKey,
          encryptedData: e.detail.encryptedData
        },
        success: function (res) {
          console.log(res)
          if (res.data.gstage == '1') {
            var rdata = JSON.parse(res.data.rdata);
            console.log(rdata)
            var u_phone = rdata.phoneNumber
            //更新数据
            app.util.request({
              'url': 'entry/wxapp/user.updatephone',
              data: {
                openid: wx.getStorageSync('openid'),
                u_phone: u_phone
              },
              success: function (res) {
                console.log(res)
              }
            })
            that.setData({
              phone: rdata.phoneNumber
            });
            wx.showToast({
              title: '绑定手机号码成功!',
              icon: 'none',
            });
          }
        },
      })
    }
  },
  //查询我是否是机构
  getjigouif() {
    var that = this
    app.util.request({
      url: "entry/wxapp/regin.jigouif",
      data: {
        openid: wx.getStorageSync('openid')
      },
      success: function (resing) {
        console.log(resing)
        that.setData({
          state: resing.data.state
        })
      }
    })
  },
})